package netty.session;

import io.netty.channel.Channel;

import java.util.concurrent.atomic.AtomicInteger;

public class NettySession {
    private String sessionId; // 可以是设备标识符，比如SIM卡号
    private Channel channel;
    private AtomicInteger sequenceNo = new AtomicInteger(0); // 消息流水号 word(16) 按发送顺序从 0 开始循环累加

    public NettySession() { }

    public NettySession(String sessionId, Channel channel) {
        this.sessionId = sessionId;
        this.channel = channel;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Channel getChannel() {
        return channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }
    public int nextSequenceNo() {
        int seq = sequenceNo.incrementAndGet();
        if (seq >= 0xffff) {
            sequenceNo.set(1);
            seq = 1;
        }
        return seq;
    }
}
